package com.enjoy.mjbaseframe.util;

import android.os.Environment;

import java.io.File;

/**
 * 文件处理工具类
 * Created by Administrator on 2018/3/14.
 */

public class FileUtil {

    /**
     * 获取根目录
     *
     * @return
     */
    public static String getRootPath() {
        String rootPath;
        boolean sdCardExist = Environment.getExternalStorageState()
                .equals(Environment.MEDIA_MOUNTED);   //判断sd卡是否存在
        if (sdCardExist) {
            rootPath = Environment.getExternalStorageDirectory().getPath();
        } else {
            rootPath = AppUtil.getApp().getCacheDir().getPath();
        }
        return rootPath;
    }

    //判断文件是否存在
    public static boolean fileIsExists(String strFile) {
        try {
            File f = new File(strFile);
            if (!f.exists()) {
                return false;
            }
        } catch (Exception e) {
            return false;
        }

        return true;
    }
}
